home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
program
/
tsfaqp34.zip
/
FAQPAS2.TXT
< prev
next >
Wrap
Internet Message Format
|
1996-09-07
|
46KB
From ts@uwasa.fi Sat Sep 7 00:00:00 1996
Subject: FAQPAS2.TXT contents
Copyright (c) 1993-1996 by Timo Salmi
All rights reserved
FAQPAS2.TXT More frequently (and not so frequently) asked Turbo
Pascal questions with Timo's answers. The items are in no particular
order.
You are free to quote brief passages from this file provided you
clearly indicate the source with a proper acknowledgment.
Comments and corrections are solicited. But if you wish to have
individual Turbo Pascal consultation, please post your questions to
a suitable Usenet newsgroup like news:comp.lang.pascal.borland. It
is much more efficient than asking me by email. I'd like to help,
but I am very pressed for time. I prefer to pick the questions I
answer from the Usenet news. Thus I can answer publicly at one go if
I happen to have an answer. Besides, newsgroups have a number of
readers who might know a better or an alternative answer. Don't be
discouraged, though, if you get a reply like this from me. I am
always glad to hear from fellow Turbo Pascal users.
....................................................................
Prof. Timo Salmi Co-moderator of news:comp.archives.msdos.announce
Moderating at ftp:// & http://garbo.uwasa.fi archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
ts@uwasa.fi http://uwasa.fi/~ts BBS 961-3170972; FIN-65101, Finland
--------------------------------------------------------------------
26) How to get ansi control codes working in Turbo Pascal writes?
27) How to evaluate a function given as a string to the program?
28) How does one detect whether input (or output) is redirected?
29) How does one set the 43/50 line text mode?
30) How can I assign a value to an environment variable in TP?
31) How does one store, and then restore the original screen?
32) How can I convert a TPU unit of one TP version to another?
33) Which error is e.g. Runtime error 205, etc
34) Why can't I open read-only files? I get "File access denied".
35) How do I obtain high and low parts of a byte variable?
36) How can I set a hi-intensity color background in the text mode?
37) Where can I find a program to convert (Turbo) Pascal to C?
38) How can I read input without echoing to the screen?
39) How can I edit the readln input stream?
40) How can I write (brand) something into my executables?
41) What is wrong with my program? It hangs without a clear pattern?
42) How do I convert a decimal word into a hexadecimal string, etc?
43) How to determine the last drive?
44) How can I put a running clock into my Turbo Pascal program?
45) How to establish if a name refers to a directory or not?
46) How does one disable alt-ctrl-del?
47) How can I test whether a file exists?
48) What is the name of the current Turbo Pascal program?
49) How is the code for rebooting the PC written in Turbo Pascal?
50) How can I write inline code?
--------------------------------------------------------------------
From ts@uwasa.fi Sat Sep 7 00:00:26 1996
Subject: Using ansi codes in a TP program
26. *****
Q: How to get ansi control codes working in Turbo Pascal writes?
A: It is very simple, but one has to be aware of the pitfalls.
Let's start from the assumption that ansi.sys or a corresponding
driver has been loaded, and that you know ansi codes. If you don't,
you'll find that information in the standard MS-DOS manual. To apply
ansi codes you just include the ansi codes in your write statements.
For example the following first clears the screen and then puts the
text at location 10,10:
write (#27, '[2J'); (* the ascii code for ESC is 27 *)
write (#27, '[10;10HUsing ansi codes can be fun');
If you want to test (as you should) whether ansi.sys or some some
replacement driver has been loaded, you can use the ISANSIFN
function from my ftp://garbo.uwasa.fi/pc/ts/tspa3570.zip.
Now the catches. If you have a
uses Crt;
statement in your program, direct screen writes will be used, and
the ansi codes won't work. You have either to leave out the Crt
unit, or include
assign (output, '');
rewrite (output);
:
close (output);
Occasionally I have seen it suggested that one should just set
DirectVideo := false;
This is a popular misconception. It won't produce the desired
result. I'm not claiming to know the reason for this quirk of Turbo
Pascal. Rather it is an observation I've made.
-From: Bengt Oehman d92bo@efd.lth.se with a later dicussion with Bob
Peck bpeck@prairienet.org and help from Duncan Murdoch
dmurdoch@mast.queensu.ca. The `DirectVideo:=False' statement only
tells the Crt unit to use BIOS calls instead of using direct
video-memory writes. A demo program to illustrate the screen writing
modes follows:
Program ScreenWriteDemo;
USES Crt;
BEGIN
Writeln('This is written directly to the video memory');
DirectVideo:=False;
Writeln('This is written via BIOS interrupt calls (int 10h)');
Assign(Output,'');
Append(Output);
Writeln('This is written via DOS calls (int 21h)');
END.
A note: The latter could be also written as
Writeln(Output, 'This is written via DOS calls (int 21h)');
since the writeln default is the standard output.
--------------------------------------------------------------------
From ts@uwasa.fi Sat Sep 7 00:00:27 1996
Subject: Writing an expression parser
27. *****
Q: How to evaluate a function given as a string to the program?
A: To do this you have to have a routine for parsing and evaluating
your expression. This is a complicated task requiring a clever use
of recursion. You can find such code in Stephen O'Brien (1988),
Turbo Pascal, The Complete Reference. Borland-Osborne/McGraw-Hill,
Chapter 10. Another, simpler piece of code can be found in Michael
Yester (1989), Using Turbo Pascal, Que, Chapter 5.
I've also written such a function evaluation program myself, and
much of it is based on the ideas in O'Brien with my own corrections
and enhancements. The resulting program is available as fn.exe
function evaluator in the ftp://garbo.uwasa.fi/pc/ts/tsfunc13.zip
package (or whatever version number is the latest). Note however,
that the source code is not included, nor available.
Tips from Justin Lee (ossm1jl@rex.uokhsc.edu):
67666 Sep 22 1994 ftp://garbo.uwasa.fi/pc/turboobj/parstp30.zip
parstp30.zip Recursive expression TP7.0/BP/VB/C++ parser, R.Loewy
An excellent parser is included with all the Turbo Pascal versions
since TP4.0 as part of the MCALC or TCALC spreadsheet example
program. See mcparse.pas or tcparse.pas.
--------------------------------------------------------------------
From ts@uwasa.fi Sat Sep 7 00:00:28 1996
Subject: Detecting redirection
28. *****
Q: How does one detect whether input (or output) is redirected?
A: As we know input to a program can come from a file, from the
console, or from a pipe or redirection. Examples of the latter are
type text.dat | program
program < text.dat
A Turbo Pascal program can be made to detect the redirections using
Interrupt 21Hex, function 44Hex, subfunction 00Hex. See PC Magazine
April 16, 1991, p. 374 for the code, and Duncan (1988), Advanced
MS-DOS Programming, pp. 412-413 for more information. Alternatively,
you can utilize the preprogrammed routines
PIPEDIFN Is the standard input from redirection
PIPEDNFN Is the standard output redirected to nul
PIPEDOFN Is the standard output redirected
from my ftp://garbo.uwasa.fi/pc/ts/tspa3570.zip units.
--------------------------------------------------------------------
From ts@uwasa.fi Sat Sep 7 00:00:29 1996
Subject: Setting the 43/50 line text mode
29. *****
Q: How does one set the 43/50 line text mode?
A: Quite simple. Just apply TextMode (C80 + font8x8). Requires a
"uses Crt;". First, however, you should test that you have a at
least an EGA video adapter. (See DetectGraph in your TP manual).
Also see TSUTLE.NWS in ftp://garbo.uwasa.fi/pc/ts/tsutle22.zip (or
whichever version number is the current) for the